<!DOCTYPE html>
<html lang="en">

<head>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
    <style>
        .header span {
            background: #009680;
            font-size: 18px;
            margin-left: 10px;
            padding: 5px;
        }
        
        .header button {
            float: right;
            margin-right: 10px;
        }
    </style>
</head>

<body style="padding: 10px;">
    <div class="header">
        <span>管理员列表</span>
        <button class="layui-btn  layui-btn-warm layui-btn-sm" onclick="add()">添加</button>
        <hr style="border:solid 1px;">
    </div>
    <table class="layui-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>真实姓名</th>
                <th>角色</th>
                <th>状态</th>
                <th>添加时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {volist name="data.lists" id="vo"}
            <tr>
                <th>{$vo.id}</th>
                <th>{$vo.username}</th>
                <th>{$vo.truename}</th>
                <th>{$vo.gid}</th>
                <th>{$vo.status==0?'正常':'<span style="color: red;">禁用</span>'}</th>
                <th>{:date('Y-m-d H:i:s',$vo.add_time)}</th>
                <th>
                    <button class="layui-btn layui-btn-xs" onclick="add({$vo.id})">编辑</button>
                    <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del({$vo.id})">删除</button>
                </th>
            </tr>
            {/volist}


        </tbody>
    </table>

    <script>
        layui.use(['layer'], function() {
            layer = layui.layer;
            $ = layui.jquery;

        });
        //添加编辑

        function add(id) {
            layer.open({
                type: 2,
                title: id>0?'编辑管理员':'添加管理员',
                shade: 0.5,
                area: ['480px', '500px'],
                content: '/admins.php/admins/Admin/add?id='+id
            });

        }

        //删除

        function del(id) {
            layer.confirm('确定删除？', {
              btn: ['确定','取消'] 
          }, function(){
            $.post('/admins.php/admins/Admin/delete',{'id':id},function(res){
                if(res.code>0){
                    layer.alert('删除失败',{'icon':2});
                }else{
                    layer.msg('删除成功',{'icon':1});
                    setTimeout(function(){
                        window.location.reload()
                    },1000);
                };

            })
            
        }, function(){
        }
        ,'json');
        }

    </script>



</body>

</html>